/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFBuscaEndereco2.java
 *
 * Created on 29/05/2012, 13:18:50
 */

package ecommercial;

import ecommercial.Classes.Bairros;
import ecommercial.Classes.Cidades;
import ecommercial.Classes.ClassConecta;
import ecommercial.Classes.ComboItem;
import ecommercial.Classes.Estados;
import ecommercial.Classes.Funcoes;
import ecommercial.Classes.Logradouros;
import ecommercial.Classes.Paises;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author vitiazze
 */
public class jFBuscaEndereco2 extends javax.swing.JDialog {

    /** Creates new form jFBuscaEndereco2 */
    public jFBuscaEndereco2() {
        initComponents();

        ClassConecta.conecta();
        setTitle("Busca Endereço");
        buscarjButtonActionPerformed(null);
//        estadosjComboBox.setEnabled(false);
//        cidadejComboBox.setEnabled(false);
//        bairrosjComboBox.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        mensagemjLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        logradourojTextField = new javax.swing.JTextField();
        logradourosjButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        paisesjComboBox = new javax.swing.JComboBox();
        estadosjComboBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        cidadejComboBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        bairrosjComboBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradeLogradourosjTable = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        cancelarjButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecommercial.EcommercialApp.class).getContext().getResourceMap(jFBuscaEndereco2.class);
        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jPanel2.border.titleFont"), resourceMap.getColor("jPanel2.border.titleColor"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setName("jPanel3"); // NOI18N

        mensagemjLabel.setText(resourceMap.getString("mensagemjLabel.text")); // NOI18N
        mensagemjLabel.setName("mensagemjLabel"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        logradourojTextField.setText(resourceMap.getString("logradourojTextField.text")); // NOI18N
        logradourojTextField.setName("logradourojTextField"); // NOI18N
        logradourojTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                logradourojTextFieldKeyReleased(evt);
            }
        });

        logradourosjButton.setIcon(resourceMap.getIcon("logradourosjButton.icon")); // NOI18N
        logradourosjButton.setText(resourceMap.getString("logradourosjButton.text")); // NOI18N
        logradourosjButton.setContentAreaFilled(false);
        logradourosjButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        logradourosjButton.setName("logradourosjButton"); // NOI18N
        logradourosjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logradourosjButtonActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        paisesjComboBox.setName("paisesjComboBox"); // NOI18N
        paisesjComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                paisesjComboBoxItemStateChanged(evt);
            }
        });
        paisesjComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paisesjComboBoxActionPerformed(evt);
            }
        });

        estadosjComboBox.setName("estadosjComboBox"); // NOI18N
        estadosjComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                estadosjComboBoxItemStateChanged(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        cidadejComboBox.setName("cidadejComboBox"); // NOI18N
        cidadejComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cidadejComboBoxItemStateChanged(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        bairrosjComboBox.setName("bairrosjComboBox"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(logradourojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(logradourosjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
                    .addComponent(mensagemjLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(paisesjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(estadosjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cidadejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(bairrosjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cidadejComboBox, estadosjComboBox, paisesjComboBox});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mensagemjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(paisesjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(estadosjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cidadejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bairrosjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(logradourojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(logradourosjButton)))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setName("jPanel4"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        gradeLogradourosjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        gradeLogradourosjTable.setName("gradeLogradourosjTable"); // NOI18N
        gradeLogradourosjTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gradeLogradourosjTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(gradeLogradourosjTable);
        gradeLogradourosjTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("gradeLogradourosjTable.columnModel.title0")); // NOI18N
        gradeLogradourosjTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("gradeLogradourosjTable.columnModel.title1")); // NOI18N
        gradeLogradourosjTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("gradeLogradourosjTable.columnModel.title2")); // NOI18N
        gradeLogradourosjTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("gradeLogradourosjTable.columnModel.title3")); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 757, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setBackground(resourceMap.getColor("buscarjButton.background")); // NOI18N
        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        jButton2.setBackground(resourceMap.getColor("jButton2.background")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        cancelarjButton.setBackground(resourceMap.getColor("cancelarjButton.background")); // NOI18N
        cancelarjButton.setIcon(resourceMap.getIcon("cancelarjButton.icon")); // NOI18N
        cancelarjButton.setText(resourceMap.getString("cancelarjButton.text")); // NOI18N
        cancelarjButton.setFocusable(false);
        cancelarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancelarjButton.setName("cancelarjButton"); // NOI18N
        cancelarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cancelarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(cancelarjButton);

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 791, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    ClassConecta conexao = new ClassConecta();
    
    ComboItem combopais;
    ComboItem comboEstado;
    ComboItem comboCidade;

    public Integer codLogradouro;

//******************************************************************************************************
    public void getGradeLogradouros() throws ParseException, SQLException{
       //Consultar Logradouros
        Logradouros oLogradouro = new Logradouros();


        if ( logradourojTextField.getText().length() > 0 ){
            oLogradouro.setLogradouro(logradourojTextField.getText()+"%");
        }

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"#Id", "Tipo", "Logradouro", "Bairro", "Cidade", "Estado", "País"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradeLogradourosjTable.setModel(modeloTabela);
        gradeLogradourosjTable.getColumnModel().getColumn(0).setPreferredWidth(25);
        gradeLogradourosjTable.getColumnModel().getColumn(1).setPreferredWidth(30);
        gradeLogradourosjTable.getColumnModel().getColumn(2).setPreferredWidth(120);
        gradeLogradourosjTable.getColumnModel().getColumn(3).setPreferredWidth(80);
        gradeLogradourosjTable.getColumnModel().getColumn(4).setPreferredWidth(80);
        gradeLogradourosjTable.getColumnModel().getColumn(5).setPreferredWidth(80);
        gradeLogradourosjTable.getColumnModel().getColumn(6).setPreferredWidth(80);



try {


            resultSet = oLogradouro.getConsultar();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Logradouros.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_LOGRADOURO")),
                    resultSet.getString("TIPO"),
                    resultSet.getString("LOGRADOURO") ,
                    resultSet.getString("BAIRRO"),
                    resultSet.getString("CIDADE"),
                    resultSet.getString("ESTADO"),
                    resultSet.getString("PAIS"),
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Logradouros.class.getName()).log(Level.SEVERE, null, ex);
        }

           }


    public void getFieldLogradouro(int codLogradouro) throws ParseException{

        Logradouros oLogradouro = new Logradouros();
        ResultSet rs = null;
        oLogradouro.setCod_logradouro(codLogradouro);

        try {
            rs = oLogradouro.getConsultar();
            rs.next();

            ComboItem oItem = new ComboItem(rs.getInt("COD_TIPO_LOGRADOURO"), rs.getString("TIPO"));

            //Pegar campos
            mensagemjLabel.setText(rs.getString("TIPO") + " " + rs.getString("LOGRADOURO") + ", " + rs.getString("BAIRRO") + ", " + rs.getString("ESTADO")+
                          " - " + rs.getString("SIGLA") + " - " + rs.getString("PAIS"));


        } catch (SQLException ex) {
            Logger.getLogger(Logradouros.class.getName()).log(Level.SEVERE, null, ex);
        }
    }




    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            getGradeLogradouros();
        } catch (ParseException ex) {
            Logger.getLogger(jFBuscaEndereco2.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(jFBuscaEndereco2.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            // TODO add your handling code here:
            Paises oPais = new Paises();
            ResultSet rs = null;
            rs = oPais.getConsultar();
            paisesjComboBox.removeAllItems();
            while (rs.next()) {
                paisesjComboBox.addItem(new ComboItem(rs.getInt(1), rs.getString(2)));
            }
            paisesjComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(jFPaises.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void gradeLogradourosjTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gradeLogradourosjTableMouseClicked
        // TODO add your handling code here:
        codLogradouro = Integer.parseInt(gradeLogradourosjTable.getValueAt(gradeLogradourosjTable.getSelectedRow(), 0).toString());
            if (codLogradouro == 0) {
                return;
            }
        try {
            getFieldLogradouro(codLogradouro);
        } catch (ParseException ex) {
            Logger.getLogger(jFLogradouros.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_gradeLogradourosjTableMouseClicked

    private void logradourosjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logradourosjButtonActionPerformed
        // TODO add your handling code here:
        jFLogradouros oFormLogradouro = new jFLogradouros();

        oFormLogradouro.setTitle("Cadastro de Logradouros");
        oFormLogradouro.setDefaultCloseOperation(jFLogradouros.DO_NOTHING_ON_CLOSE);
        oFormLogradouro.pack();
        oFormLogradouro.setModal(true);
        oFormLogradouro.setLocationRelativeTo(null);
        oFormLogradouro.setVisible(true);
        buscarjButtonActionPerformed(null);


    }//GEN-LAST:event_logradourosjButtonActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void cancelarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarjButtonActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_cancelarjButtonActionPerformed

    private void logradourojTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_logradourojTextFieldKeyReleased
        // TODO add your handling code here:
        try {
            Logradouros oLogradouro = new Logradouros();
            oLogradouro.setLogradouro(logradourojTextField.getText());
            ResultSet rs = null;
            rs = oLogradouro.getConsultar();
            getGradeLogradouros();
        } catch (ParseException ex) {
            Logger.getLogger(jFLogradouros.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(jFLogradouros.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_logradourojTextFieldKeyReleased

    private void paisesjComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_paisesjComboBoxItemStateChanged
        // TODO add your handling code here:
        try {
            Estados oEstado = new Estados();
            ResultSet rs = null;

            combopais = (ComboItem) paisesjComboBox.getSelectedItem();
            oEstado.setCod_pais(combopais.getId());
            rs = oEstado.getConsultarEstados();          
            estadosjComboBox.removeAllItems();
            while (rs.next()) {
                estadosjComboBox.addItem(new ComboItem(rs.getInt("COD_ESTADO"), rs.getString("ESTADO")));
            }
            estadosjComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(jFEstados.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_paisesjComboBoxItemStateChanged

    private void estadosjComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_estadosjComboBoxItemStateChanged
        // TODO add your handling code here:
        try {
            Cidades oCidade = new Cidades();
            ResultSet rs = null;


            comboEstado = (ComboItem) estadosjComboBox.getSelectedItem();

            if (comboEstado == null){

                

                JOptionPane.showMessageDialog(null, "Não existem estados cadastrados. Favor cadastrar um estado", "MENSAGEM DO SISTEMA", JOptionPane.INFORMATION_MESSAGE );

                jFEstados oFormEstado = new jFEstados();

                oFormEstado.pack();
                oFormEstado.setLocationRelativeTo(null);
                oFormEstado.setModal(true);
                oFormEstado.setVisible(true);
                paisesjComboBox.updateUI();

            }else{

            oCidade.setCod_estado(comboEstado.getId());
            rs = oCidade.getConsultarCidade();
            cidadejComboBox.removeAllItems();
            while (rs.next()) {
                cidadejComboBox.addItem(new ComboItem(rs.getInt("COD_CIDADE"), rs.getString("CIDADE")));
            }
            cidadejComboBox.updateUI();
        } }catch (SQLException ex) {
            Logger.getLogger(jFEstados.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_estadosjComboBoxItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cidadejComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cidadejComboBoxItemStateChanged
        // TODO add your handling code here:
        try {
            Bairros oBairro = new Bairros();
            ResultSet rs = null;

            comboCidade = (ComboItem) cidadejComboBox.getSelectedItem();

            if (comboCidade == null){


                JOptionPane.showMessageDialog(null, "Não existem cidades cadastradas. Favor cadastrar uma cidade", "MENSAGEM DO SISTEMA", JOptionPane.INFORMATION_MESSAGE );

                jFCidades oFormCidade = new jFCidades();

                oFormCidade.pack();
                oFormCidade.setLocationRelativeTo(null);
                oFormCidade.setModal(true);
                oFormCidade.setVisible(true);

            }else{

            oBairro.setCod_Cidade(comboCidade.getId());
            rs = oBairro.getConsultarBairros();
            bairrosjComboBox.removeAllItems();
            while (rs.next()) {
                bairrosjComboBox.addItem(new ComboItem(rs.getInt("COD_BAIRRO"), rs.getString("BAIRRO")));
            }
            bairrosjComboBox.updateUI();
        }} catch (SQLException ex) {
            Logger.getLogger(jFEstados.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_cidadejComboBoxItemStateChanged

    private void paisesjComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_paisesjComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_paisesjComboBoxActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFBuscaEndereco2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox bairrosjComboBox;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JButton cancelarjButton;
    private javax.swing.JComboBox cidadejComboBox;
    private javax.swing.JComboBox estadosjComboBox;
    private javax.swing.JTable gradeLogradourosjTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField logradourojTextField;
    private javax.swing.JButton logradourosjButton;
    private javax.swing.JLabel mensagemjLabel;
    private javax.swing.JComboBox paisesjComboBox;
    // End of variables declaration//GEN-END:variables

}
